package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/order")
@Controller
@ResponseBody
public class OrderController {

    @Reference
    private OrderService orderService;

    @RequestMapping("/submitOrder")
    public Result submitOrder(@RequestBody Map<String,Object> map){
        try {
            Result result=orderService.submitOrder(map);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERSETTING_FAIL);
        }
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        boolean flag=false;
        String message=null;
        Map map = new HashMap();
        try {
            map = orderService.findOrderById(id);
            flag=true;
            message=MessageConstant.QUERY_ORDER_SUCCESS;
        } catch (Exception e) {
            message=MessageConstant.QUERY_ORDER_FAIL;
            e.printStackTrace();
        }
        return new Result(flag,message,map);
    }
}
